package edu.sctu.practice.class02.xuejiahua.practise.test04;

/**
 * Created by Dom_xuejiahua on 2015/12/13.
 */
public class Try_Catch {

/*
* divider(除数)
* result(结果)
* try-catch捕获while循环
* 每次循环，divider减一，result=result+100/divider
* 如果：捕获异常，打印输出“抛出异常！！！，返回-1”
* 否则：返回result
* */

        public int test(){
            int divider = 10;
            int result = 100;
            try{
                while (divider > -1){
                    divider--;
                    result = result+100/divider;
                }
                return result;

            }catch(Exception e){
                e.printStackTrace();
                System.out.println("循环抛出异常了！！");
                return -1;
            }

        }

    /*
* divider(除数)
* result(结果)
* try-catch捕获while循环
* 每次循环，divider减一，result=result+100/divider
* 如果：捕获异常，打印输出“抛出异常！！！，返回result=999”
* 否则：返回result
* finally:打印输出“这是finally” 同时打印输出result的值
* */
    public int test2(){
        int divider = 10;
        int result = 100;
        try{
            while (divider > -1){
                divider--;
                result = result+100/divider;
            }
            return result;

        }catch(Exception e){
            e.printStackTrace();
            System.out.println("循环抛出异常了！！");
            return result=999;
        }finally {
            System.out.println("这是finally!");
            System.out.println("我是result，值是："+result);
        }

    }
    /*
    * divider(除数)
    * result(结果)
    * try-catch捕获while循环
    * 每次循环，divider减一，result=result+100/divider
    * 如果：捕获异常，打印输出“抛出异常！！！，返回result=999”
            * 否则：返回result
    * finally:打印输出“这是finally” 同时打印输出result的值
    * 打印test3运行完毕，同时输出1111
    * */
    public int test3(){
        int divider = 10;
        int result = 100;
        try{
            while (divider > -1){
                divider--;
                result = result+100/divider;
            }

        }catch(Exception e){
            e.printStackTrace();
            System.out.println("循环抛出异常了！！");

        }finally {
            System.out.println("这是finally!");
            System.out.println("我是result，值是："+result);
        }
        System.out.println("test3运行完毕，请指示！！，返回值为1111");
      return 1111;

    }

    }

